"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));

var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));

/* eslint-disable no-restricted-syntax */

/* eslint-disable no-continue */

/* eslint-disable @typescript-eslint/no-unused-vars */

/* eslint-disable no-self-compare */

/* eslint-disable eqeqeq */

/* eslint-disable no-plusplus */
// do not edit .js files directly - edit src/index.jst
function isDeepEqualReact(a, b, ignoreKeys, debug) {
  if (a === b) return true;

  if (a && b && (0, _typeof2.default)(a) === 'object' && (0, _typeof2.default)(b) === 'object') {
    if (a.constructor !== b.constructor) return false;
    var length;
    var i;
    var keys;

    if (Array.isArray(a)) {
      length = a.length;
      if (length != b.length) return false;

      for (i = length; i-- !== 0;) {
        if (!isDeepEqualReact(a[i], b[i], ignoreKeys, debug)) return false;
      }

      return true;
    }

    if (a instanceof Map && b instanceof Map) {
      if (a.size !== b.size) return false;

      var _iterator = (0, _createForOfIteratorHelper2.default)(a.entries()),
          _step;

      try {
        for (_iterator.s(); !(_step = _iterator.n()).done;) {
          i = _step.value;
          if (!b.has(i[0])) return false;
        }
      } catch (err) {
        _iterator.e(err);
      } finally {
        _iterator.f();
      }

      var _iterator2 = (0, _createForOfIteratorHelper2.default)(a.entries()),
          _step2;

      try {
        for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
          i = _step2.value;
          if (!isDeepEqualReact(i[1], b.get(i[0]), ignoreKeys, debug)) return false;
        }
      } catch (err) {
        _iterator2.e(err);
      } finally {
        _iterator2.f();
      }

      return true;
    }

    if (a instanceof Set && b instanceof Set) {
      if (a.size !== b.size) return false;

      var _iterator3 = (0, _createForOfIteratorHelper2.default)(a.entries()),
          _step3;

      try {
        for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
          i = _step3.value;
          if (!b.has(i[0])) return false;
        }
      } catch (err) {
        _iterator3.e(err);
      } finally {
        _iterator3.f();
      }

      return true;
    }

    if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
      // @ts-ignore
      length = a.length; // @ts-ignore

      if (length != b.length) return false;

      for (i = length; i-- !== 0;) {
        if (a[i] !== b[i]) return false;
      }

      return true;
    }

    if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
    if (a.valueOf !== Object.prototype.valueOf && a.valueOf) return a.valueOf() === b.valueOf();
    if (a.toString !== Object.prototype.toString && a.toString) return a.toString() === b.toString(); // eslint-disable-next-line prefer-const

    keys = Object.keys(a);
    length = keys.length;
    if (length !== Object.keys(b).length) return false;

    for (i = length; i-- !== 0;) {
      if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
    }

    for (i = length; i-- !== 0;) {
      var key = keys[i];
      if (ignoreKeys === null || ignoreKeys === void 0 ? void 0 : ignoreKeys.includes(key)) continue;

      if (key === '_owner' && a.$$typeof) {
        // React-specific: avoid traversing React elements' _owner.
        //  _owner contains circular references
        // and is not needed when comparing the actual elements (and not their owners)
        continue;
      }

      if (!isDeepEqualReact(a[key], b[key], ignoreKeys, debug)) {
        if (debug) {
          console.log(key);
        }

        return false;
      }
    }

    return true;
  } // true if both NaN, false otherwise


  return a !== a && b !== b;
}

var _default = isDeepEqualReact;
exports.default = _default;